<script setup lang="ts">
import useUserStore from '@/stores/user'
import { computed } from 'vue'

const userStore = useUserStore()

const { permission, unitId } = defineProps<{
  permission: string
  unitId?: number
}>()

const show = computed(() => {
  if (!permission) {
    return false
  } else if (userStore.isAdmin) {
    return true
  } else {
    let permissionText = permission
    if (unitId) {
      permissionText += `:${unitId}`
    }
    return userStore.hasAnyPermission(permissionText)
  }
})
</script>

<template>
  <template v-if="show">
    <slot v-if="$slots.default" />
  </template>
</template>

<style scoped lang="scss"></style>
